package main;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import login.Connects;

public class TarrPackage extends JFrame {

	private JPanel contentPane;
	JLabel lblCuocNhan,lblCuocGoi, lblApDung,lblTenGC,lblMaGC;
	JComboBox comboGC;
	/**
	 * Launch the application.
	 */
	public static Connection con;
	static String username;
	static String password;

	// Kết nối đến cơ sở dữ liệu
	public void connect() throws Exception {

		String user = "root";
		String pass = "";
		String url = "jdbc:mysql://localhost:3306/qlsodt";
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			con = DriverManager.getConnection(url, user, pass);

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.print("Not connect");
		}
	}
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TarrPackage frame = new TarrPackage();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @throws Exception 
	 */
	public void loadCombo() throws Exception{
		connect();
		String load="select TenGC from goicuoc";
		Statement st=con.createStatement();
		st.executeQuery(load);
		ResultSet rs=st.getResultSet();
		while(rs.next()){
			comboGC.addItem(rs.getString("TenGC"));
		}
		
	}
	public void showGC(){
		try {
			connect();
			String show="select * from goicuoc where TenGC='"+comboGC.getSelectedItem().toString()+"'";
			Statement stshow=con.createStatement();
			stshow.executeQuery(show);
			ResultSet rsshow=stshow.getResultSet();
			while(rsshow.next()){
				lblTenGC.setText(rsshow.getString("TenGC"));
				lblMaGC.setText(rsshow.getString("MaGC"));
				lblApDung.setText(rsshow.getString("Apply"));
				lblCuocGoi.setText(rsshow.getString("PhiGoi"));
				lblCuocNhan.setText(rsshow.getString("PhiNhan"));
				
			}
		
		
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public TarrPackage() throws Exception {

		setBounds(100, 100, 384, 250);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		comboGC = new JComboBox();
		comboGC.setBounds(116, 11, 240, 20);
		contentPane.add(comboGC);
		comboGC.addItem("");
		loadCombo();
		comboGC.addItemListener(new ItemListener() {
			
			@Override
			public void itemStateChanged(ItemEvent arg0) {
				// TODO Auto-generated method stub
				showGC();
			}
		});
	
		
		JLabel lblTnGiCc = new JLabel("Tên gói cước");
		lblTnGiCc.setBounds(10, 14, 96, 14);
		contentPane.add(lblTnGiCc);
		
		JLabel lblTnGiCc_1 = new JLabel("Tên gói cước:");
		lblTnGiCc_1.setBounds(10, 42, 85, 14);
		contentPane.add(lblTnGiCc_1);
		
		JLabel lblMGiCc = new JLabel("Mã gói cước:");
		lblMGiCc.setBounds(10, 90, 85, 14);
		contentPane.add(lblMGiCc);
		
		JLabel lblCcGi = new JLabel("Cước gọi:");
		lblCcGi.setBounds(10, 115, 68, 14);
		contentPane.add(lblCcGi);
		
		JLabel lblCcTinNhn = new JLabel("Cước tin nhắn:");
		lblCcTinNhn.setBounds(10, 140, 85, 14);
		contentPane.add(lblCcTinNhn);
		
		JButton btnOk = new JButton("OK");
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		btnOk.setBounds(145, 176, 89, 23);
		contentPane.add(btnOk);
		
		 lblTenGC = new JLabel("null");
		lblTenGC.setBounds(93, 42, 263, 14);
		contentPane.add(lblTenGC);
		
		 lblApDung = new JLabel("null");
		lblApDung.setBounds(76, 65, 280, 14);
		contentPane.add(lblApDung);
		
		JLabel lblpDng = new JLabel("Áp dụng:");
		lblpDng.setBounds(10, 65, 68, 14);
		contentPane.add(lblpDng);
		
		 lblMaGC = new JLabel("null");
		lblMaGC.setBounds(93, 90, 263, 14);
		contentPane.add(lblMaGC);
		
		 lblCuocGoi = new JLabel("0");
		lblCuocGoi.setBounds(76, 115, 68, 14);
		contentPane.add(lblCuocGoi);
		
		 lblCuocNhan = new JLabel("0");
		lblCuocNhan.setBounds(105, 140, 76, 14);
		contentPane.add(lblCuocNhan);
		
		JLabel lblVnpht = new JLabel("VNĐ/phút");
		lblVnpht.setBounds(111, 115, 96, 14);
		contentPane.add(lblVnpht);
		
		JLabel lblVnsms = new JLabel("VNĐ/SMS");
		lblVnsms.setBounds(134, 140, 62, 14);
		contentPane.add(lblVnsms);
	}
}
